import { WeApp } from '../../../../common/common';
import { config } from '../../../../etc/config';
import httpClient from '../../../../common/http-client';
import { Consignee } from '../../../../model/consignee';
import wxService from '../../../../common/wxService'
import tools from '../../../../common/tools'
import { prompt } from '../../../../assets/components/wux';
import utils from '../../../../utils/utils';

const app: WeApp = getApp() as WeApp;
interface RefereeListPageData {
    consignee?: Array<Consignee>,
    isSelect?: boolean,
    noId?: string,
}

interface RefereeListPage extends IPage { }

class RefereeListPage {
    public data: RefereeListPageData = {
    }

    public onLoad(): void {
        this.getList();
    }

    public getList() {
        httpClient.get<{
            headImg: string, 
            name: string, 
            isVip: boolean
        }>(config.user.referee_list)
            .then((res) => {
                if (res.succeed) {
                    this.setData({
                        datas: res.values
                    })
                    const prop = prompt.init('msg1', {
                        title: '',
                        text: '暂时没有数据，赶快去邀请一个！',
                        icon: 'http://r.59im.com/wx/tips/lack_without_address_icon@2x.png'
                    });
                    if (!res.values || !res.values.length) {
                        prop.show();
                    }
                    else {
                        prop.hide();
                    }
                }
                else {
                    wxService.showToast(res.msg);
                }
            }).catch(e => {
                utils.loadError(() => {
                    this.getList();
                })
            })
    }

}

Page(new RefereeListPage());